<!DOCTYPE html>
<html lang="zh-Hans">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.3.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/blog/images/logo.svg" color="#222">

<link rel="stylesheet" href="/blog/css/main.css">

<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
<link rel="stylesheet" href="/blog/lib/font-awesome/css/font-awesome.min.css">


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    hostname: new URL('https://guodh.gitee.io/blog').hostname,
    root: '/blog/',
    scheme: 'Pisces',
    version: '7.7.1',
    exturl: false,
    sidebar: {"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},
    copycode: {"enable":true,"show_result":true,"style":null},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
    bookmark: {"enable":false,"color":"#222","save":"auto"},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    comments: {"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: 'search.xml',
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}
  };
</script>

  <meta name="description" content="话说笔者最近在看一些网络通信方面的东西，恰巧看到一位大牛做了一个NIO的server的Demo。Demo虽小，但是五脏俱全，能够很好的一窥NIO服务的架构。源码地址：https:&#x2F;&#x2F;github.com&#x2F;jjenkov&#x2F;java-nio-server 整体结构 整体结构如图所示，刚开始可能不知道这个Server是一个怎样的结构，但是作者很善良的给了个example，那么就先从main方法进入。">
<meta property="og:type" content="article">
<meta property="og:title" content="如何自己实现一个NIO的Server">
<meta property="og:url" content="https://guodh.gitee.io/blog/2017/04/23/2018/NIOServer/index.html">
<meta property="og:site_name" content="蛋蛋的小屋">
<meta property="og:description" content="话说笔者最近在看一些网络通信方面的东西，恰巧看到一位大牛做了一个NIO的server的Demo。Demo虽小，但是五脏俱全，能够很好的一窥NIO服务的架构。源码地址：https:&#x2F;&#x2F;github.com&#x2F;jjenkov&#x2F;java-nio-server 整体结构 整体结构如图所示，刚开始可能不知道这个Server是一个怎样的结构，但是作者很善良的给了个example，那么就先从main方法进入。">
<meta property="og:locale">
<meta property="og:image" content="https://olwr1lamu.qnssl.com/NIOpackge.png">
<meta property="og:image" content="https://olwr1lamu.qnssl.com/jiagou.png">
<meta property="og:image" content="https://olwr1lamu.qnssl.com/Socket2.png">
<meta property="article:published_time" content="2017-04-23T08:29:58.000Z">
<meta property="article:modified_time" content="2018-06-18T05:05:15.000Z">
<meta property="article:author" content="RunningEgg">
<meta property="article:tag" content="技术">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://olwr1lamu.qnssl.com/NIOpackge.png">

<link rel="canonical" href="https://guodh.gitee.io/blog/2017/04/23/2018/NIOServer/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true
  };
</script>

  <title>如何自己实现一个NIO的Server | 蛋蛋的小屋</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-meta">

    <div>
      <a href="/blog/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">蛋蛋的小屋</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <p class="site-subtitle">来了就看看吧，没有刀剑只有故事</p>
  </div>

  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/blog/" rel="section"><i class="fa fa-fw fa-home"></i>Home</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/blog/about/" rel="section"><i class="fa fa-fw fa-user"></i>About</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/blog/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>Archives</a>

  </li>
        <li class="menu-item menu-item-book">

    <a href="/blog/book/" rel="section"><i class="fa fa-fw fa-archive"></i>book</a>

  </li>
  </ul>

</nav>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-Hans">
    <link itemprop="mainEntityOfPage" href="https://guodh.gitee.io/blog/2017/04/23/2018/NIOServer/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.gif">
      <meta itemprop="name" content="RunningEgg">
      <meta itemprop="description" content="写下我的点点滴滴，写下我对这个世界的看法，还有我内心锁崇拜的技术">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="蛋蛋的小屋">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          如何自己实现一个NIO的Server
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>

              <time title="Created: 2017-04-23 16:29:58" itemprop="dateCreated datePublished" datetime="2017-04-23T16:29:58+08:00">2017-04-23</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">Edited on</span>
                <time title="Modified: 2018-06-18 13:05:15" itemprop="dateModified" datetime="2018-06-18T13:05:15+08:00">2018-06-18</time>
              </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>话说笔者最近在看一些网络通信方面的东西，恰巧看到一位大牛做了一个NIO的server的Demo。Demo虽小，但是五脏俱全，能够很好的一窥NIO服务的架构。<br>源码地址：<a href="https://github.com/jjenkov/java-nio-server">https://github.com/jjenkov/java-nio-server</a></p>
<h1 id="整体结构"><a href="#整体结构" class="headerlink" title="整体结构"></a>整体结构</h1><img src="https://olwr1lamu.qnssl.com/NIOpackge.png" width="50%" height="50%" alt="结构图"/>
整体结构如图所示，刚开始可能不知道这个Server是一个怎样的结构，但是作者很善良的给了个example，那么就先从main方法进入。

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">Server server = <span class="keyword">new</span> Server(<span class="number">9999</span>, <span class="keyword">new</span> HttpMessageReaderFactory(), messageProcessor);</span><br><span class="line">server.start();</span><br></pre></td></tr></table></figure>
<p>main方法中，主要初始化了项目中的Server，以及启动Server。好，那么就可以直接来看整个项目真正的启动类。</p>
<h2 id="Server"><a href="#Server" class="headerlink" title="Server"></a>Server</h2><p>直接来看Server中的start吧，看看一个Server需要启动哪些脚手架：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">start</span><span class="params">()</span> <span class="keyword">throws</span> IOException </span>&#123;</span><br><span class="line">	      <span class="comment">// 循环创建socket放入Queue</span></span><br><span class="line">        <span class="keyword">this</span>.socketAccepter  = <span class="keyword">new</span> SocketAccepter(tcpPort, socketQueue);</span><br><span class="line">        </span><br><span class="line">        <span class="comment">// NIO循环遍历，查询可以进行操作的channel</span></span><br><span class="line">        <span class="comment">// 这里的入参都是来自Server的初始化的时候的构造函数，而且还包含一个Factory方法，这种设计类的思路可以借鉴一下</span></span><br><span class="line">        <span class="keyword">this</span>.socketProcessor = <span class="keyword">new</span> SocketProcessor(socketQueue, readBuffer, writeBuffer,  <span class="keyword">this</span>.messageReaderFactory, <span class="keyword">this</span>.messageProcessor);</span><br><span class="line">        </span><br><span class="line">        <span class="comment">// 启动线程</span></span><br><span class="line">		    accepterThread.start();</span><br><span class="line">        processorThread.start();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>通过上面的类，我们可以看到，Server中主要启动了，两个线程，分别是accepterThread和processorThread。</p>
<h2 id="架构组成"><a href="#架构组成" class="headerlink" title="架构组成"></a>架构组成</h2><p>为了方便理解，我直接把整个NIO的架构给贴出来吧。<br><img src="https://olwr1lamu.qnssl.com/jiagou.png" alt="NIO架构图"/><br>主要包括Acceptor和SocketProcessor，两者之间通过Queue连接。</p>
<h2 id="Acceptor"><a href="#Acceptor" class="headerlink" title="Acceptor"></a>Acceptor</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 打开Socket</span></span><br><span class="line"><span class="keyword">try</span>&#123;</span><br><span class="line">     <span class="keyword">this</span>.serverSocket = ServerSocketChannel.open();</span><br><span class="line">     <span class="keyword">this</span>.serverSocket.bind(<span class="keyword">new</span> InetSocketAddress(tcpPort));</span><br><span class="line">&#125; <span class="keyword">catch</span>(IOException e)&#123;</span><br><span class="line">     <span class="keyword">return</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">while</span>(<span class="keyword">true</span>)&#123;</span><br><span class="line">      <span class="keyword">try</span>&#123;</span><br><span class="line">	       <span class="comment">// socketChannel.accept接收connection</span></span><br><span class="line">           SocketChannel socketChannel = <span class="keyword">this</span>.serverSocket.accept();</span><br><span class="line">           <span class="comment">// 将Socket放入队列</span></span><br><span class="line">           <span class="keyword">this</span>.socketQueue.add(<span class="keyword">new</span> Socket(socketChannel));</span><br><span class="line"></span><br><span class="line">          &#125; <span class="keyword">catch</span>(IOException e)&#123;</span><br><span class="line">                e.printStackTrace();</span><br><span class="line">          &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>socketChannel可以设置为非阻塞模式，serverSocketChannel.configureBlocking(false);<br>这样socketChannel接收到Connoection就会立刻返回，没有则返回null。直接将socketChannel放入Channel，由SocketProcessor去负责检查Channel是否就绪。同时，需要Processor处理，返回为null的情况。</p>
<h2 id="SocketProcessor"><a href="#SocketProcessor" class="headerlink" title="SocketProcessor"></a>SocketProcessor</h2><p>SocketProcessor中维护了一个readSelector，其中注册了来自Queue中的Socket。<br>readSelector是由Java NIO包中package java.nio.channels.Selector提供。<br>注册分几步走：</p>
<ol>
<li>遍历Queue中的Socket</li>
<li>初始化Socket中的IMessageReader，socketChannel中的configureBlocking设置为false（有个问题：为什么是在Procesor设置，而不是Acceptor中设置？）</li>
<li>将Socket注册到Selector中</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">SelectionKey key = newSocket.socketChannel.register(<span class="keyword">this</span>.readSelector, SelectionKey.OP_READ);</span><br><span class="line">key.attach(newSocket);</span><br></pre></td></tr></table></figure>
<p>通过上面两个函数，将Socket中的socketChannel注册到了Selector中，同时返回SelectionKey。<br>4. 检查readSelector<br>5. 就绪的SocketChannel，则使用Socket初始化的messageReader，读取Message<br>6. 将SelectionKey从readSelector取消，并关闭SocketChannel</p>
<h2 id="Socket类"><a href="#Socket类" class="headerlink" title="Socket类"></a>Socket类</h2><p>这里可以来看下作者设计的Socket这个类：<br><img src="https://olwr1lamu.qnssl.com/Socket2.png" width="100%" height="75%" alt="Socket结构"/><br>这里一个很好的设计是，messageRead是有Factory产生，而Factory是从messageProcessor从构造类中导入，提供了很好的扩展性。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">IMessageReader</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">init</span><span class="params">(MessageBuffer readMessageBuffer)</span></span>;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">read</span><span class="params">(Socket socket, ByteBuffer byteBuffer)</span> <span class="keyword">throws</span> IOException</span>;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> List&lt;Message&gt; <span class="title">getMessages</span><span class="params">()</span></span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="字节流"><a href="#字节流" class="headerlink" title="字节流"></a>字节流</h2><p>同时，在HttpUtil中还有个处理请求字节流的工具类</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">int</span> endIndex = HttpUtil.parseHttpRequest(<span class="keyword">this</span>.nextMessage.sharedArray, <span class="keyword">this</span>.nextMessage.offset, <span class="keyword">this</span>.nextMessage.offset + <span class="keyword">this</span>.nextMessage.length, (HttpHeaders) <span class="keyword">this</span>.nextMessage.metaData);</span><br><span class="line"><span class="keyword">if</span>(endIndex != -<span class="number">1</span>)&#123;</span><br><span class="line">	Message message = <span class="keyword">this</span>.messageBuffer.getMessage();</span><br><span class="line">	message.metaData = <span class="keyword">new</span> HttpHeaders();</span><br><span class="line">	message.writePartialMessageToMessage(nextMessage, endIndex);</span><br><span class="line">	completeMessages.add(nextMessage);</span><br><span class="line">	nextMessage = message;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>不过，知道怎么用就差不多了（其实是懒）。</p>
<h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1><p>通过整个分析，可以了解SocketChannel，Selector的用法，以及对NIO Server的架构有了一个理性的认识。对于以后自己去处理NIO的一些东西，是非常有价值的，非常鼓励大家，能够去看看这个小Demo的源码。</p>
<p>同时，推荐两个开源项目，有利用到NIO，而且都很有意思：<br>Rider: <a href="https://my.oschina.net/alchemystar/blog/865237">https://my.oschina.net/alchemystar/blog/865237</a><br>Mycat</p>
<p>另外，介绍Java的一个Buffer，DirectBuffer。不同于一般的Buffer，DirectBuffer属于内存Buffer，虽然DirectBuffer的创建相较于普通Buffer耗费时间，但是对于一些大的IO，如果需要从内存 -&gt; jvm -&gt; 内存，DirectBuffer能够提供更高的效率。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Buffer</span> </span>&#123;</span><br><span class="line">	<span class="comment">// 0 &lt;= mark &lt;= position &lt;= limit &lt;= capacity	</span></span><br><span class="line">	<span class="keyword">int</span> capacity,limit,position,mark;</span><br><span class="line">	<span class="function"><span class="keyword">public</span> Buffer <span class="title">flip</span><span class="params">()</span> </span>&#123;</span><br><span class="line">		<span class="comment">// 将limit设置为当前position，同时position设置为0，准备开始读数据</span></span><br><span class="line">	&#125;</span><br><span class="line">	<span class="function"><span class="keyword">public</span> Buffer <span class="title">rewind</span><span class="params">()</span> </span>&#123;</span><br><span class="line">		<span class="comment">// 将position设置为0，mark设置为-1，准备开始写数据</span></span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/blog/tags/%E6%8A%80%E6%9C%AF/" rel="tag"># 技术</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/blog/2017/03/20/2017/lock%E5%92%8Clockinterruptibly/" rel="prev" title="几种获得锁的方法的区别">
      <i class="fa fa-chevron-left"></i> 几种获得锁的方法的区别
    </a></div>
      <div class="post-nav-item">
    <a href="/blog/2017/05/19/2017/weex%E5%B0%8F%E5%AE%9E%E8%B7%B5/" rel="next" title="Weex小实践">
      Weex小实践 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E6%95%B4%E4%BD%93%E7%BB%93%E6%9E%84"><span class="nav-number">1.</span> <span class="nav-text">整体结构</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#Server"><span class="nav-number">1.1.</span> <span class="nav-text">Server</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9E%B6%E6%9E%84%E7%BB%84%E6%88%90"><span class="nav-number">1.2.</span> <span class="nav-text">架构组成</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Acceptor"><span class="nav-number">1.3.</span> <span class="nav-text">Acceptor</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#SocketProcessor"><span class="nav-number">1.4.</span> <span class="nav-text">SocketProcessor</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Socket%E7%B1%BB"><span class="nav-number">1.5.</span> <span class="nav-text">Socket类</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AD%97%E8%8A%82%E6%B5%81"><span class="nav-number">1.6.</span> <span class="nav-text">字节流</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E6%80%BB%E7%BB%93"><span class="nav-number">2.</span> <span class="nav-text">总结</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">RunningEgg</p>
  <div class="site-description" itemprop="description">写下我的点点滴滴，写下我对这个世界的看法，还有我内心锁崇拜的技术</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/blog/archives/">
        
          <span class="site-state-item-count">89</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">24</span>
        <span class="site-state-item-name">tags</span>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="mailto:guodh_1@163.com" title="E-Mail → mailto:guodh_1@163.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">RunningEgg</span>
</div>
  <div class="powered-by">Powered by <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> v5.3.0
  </div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">Theme – <a href="https://pisces.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Pisces</a> v7.7.1
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/blog/lib/anime.min.js"></script>
  <script src="/blog/lib/velocity/velocity.min.js"></script>
  <script src="/blog/lib/velocity/velocity.ui.min.js"></script>

<script src="/blog/js/utils.js"></script>

<script src="/blog/js/motion.js"></script>


<script src="/blog/js/schemes/pisces.js"></script>


<script src="/blog/js/next-boot.js"></script>




  















  

  

</body>
</html>
